package ph.com.gs3.formalistics.presenter.fragments.views;

import java.util.ArrayList;
import java.util.List;

import ph.com.gs3.formalistics.R;
import ph.com.gs3.formalistics.global.utilities.logging.FLLogger;
import ph.com.gs3.formalistics.global.utilities.view.ViewGroupUtils;
import ph.com.gs3.formalistics.model.valueobjects.business.document.Document.DocumentStar;
import ph.com.gs3.formalistics.model.valueobjects.business.form.FormStub;
import ph.com.gs3.formalistics.presenter.adapters.DocumentListItemViewAdapter;
import ph.com.gs3.formalistics.presenter.adapters.DocumentListItemViewAdapter.DocumentListItemActionListener;
import ph.com.gs3.formalistics.presenter.fragments.views.DocumentListViewFragment.DocumentListViewFragmentActionListener;
import ph.com.gs3.formalistics.view.valueobjects.UserActionListViewItem;
import ph.com.gs3.formalistics.view.valueobjects.UserActionListViewItem.UpdateType;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

public class MainViewFragment extends Fragment {

	// ========================================================================
	// {{ Constants

	public static final String TAG = MainViewFragment.class.getSimpleName();

	public static final String EXTRA_PENDING_NOTIFICATION_MODE = "pending_notification_mode";

	public static final String PROMPT_NO_CONNECTION = "No connection to server";
	public static final String PROMPT_HAS_CONNECTION = "Connected to server";

	public static final String COLOR_ERROR = "#dbdbdb";
	public static final String COLOR_INFO = "#00d505";

	// }}

	// ========================================================================
	// {{ Enumerations

	public static enum NotificationMode {
		NOTIFY_NONE, NOTIFY_OFFLINE, NOTIFY_ONLINE
	}

	public static enum ViewDataType {
		ALL, MY_WORK, MY_ACTIONS, STARRED, OUTBOX
	}

	public static enum ViewAddMode {
		APPEND, INSERT_TO_TOP
	}

	// }}

	// ========================================================================
	// Fields

	private List<FormStub> formFilterSelection;

	private FormStub currentlySelectedFormFilter;

	private MainViewActivityActionListener listener;

	private NotificationMode notificationMode;

	private boolean isFragmentViewInitialized;

	// ========================================================================
	// View Data & Data Adapters

	private List<UserActionListViewItem> allUserActions;
	private List<UserActionListViewItem> myWorkUserActions;
	private List<UserActionListViewItem> myUserActions;
	private List<UserActionListViewItem> starredUserActions;
	private List<UserActionListViewItem> outboxUserActions;

	// List Adapters For Views
	private DocumentListItemViewAdapter allDocumentsViewAdapter;
	private DocumentListItemViewAdapter myWorkDocumentsViewAdapter;
	private DocumentListItemViewAdapter myDocumentsViewAdapter;
	private DocumentListItemViewAdapter starredDocumentsViewAdapter;
	private DocumentListItemViewAdapter outboxDocumentsViewAdapter;

	// ========================================================================
	// Fragments

	private DocumentListViewFragment homeViewFragment;
	private DocumentListViewFragment myWorkViewFragment;
	private DocumentListViewFragment myDocumentsViewFragment;
	private DocumentListViewFragment starredDocumentsViewFragment;
	private DocumentListViewFragment outboxDocumentViewFragment;

	// ========================================================================
	// View Components

	private List<Fragment> viewFragments;
	private List<ImageView> tabIcons;

	private Button bRetryConnection;

	private ViewPager vpMainViewPager;
	private ActionBar abMainActionBar;
	private Spinner spFormFilter;
	private LinearLayout llMessageContainer;
	private TextView tvMessageNotification;

	private LinearLayout llLoadingMessageContainer;
	private TextView tvLoadingMessage;

	private Animation fadeInAnimation, fadeOutAnimation;

	private ArrayAdapter<FormStub> formfilterAdapter;

	// ~ End of Declarations
	// ========================================================================

	public static MainViewFragment createInstance(List<FormStub> initialFormFilterSelection,
	        NotificationMode initialNotificationMode) {
		MainViewFragment newInstance = new MainViewFragment();
		if (initialFormFilterSelection != null) {
			newInstance.addFormFilters(initialFormFilterSelection);
		}

		newInstance.notificationMode = initialNotificationMode;
		newInstance.initializeViewData();

		return newInstance;
	}

	public MainViewFragment() {
		resetFormFilterSelection();

		notificationMode = NotificationMode.NOTIFY_NONE;
		isFragmentViewInitialized = false;
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		try {
			listener = (MainViewActivityActionListener) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(activity.toString()
			        + " must implement MainViewActivityActionListener");
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_main, container, false);

		initializeViewAdapters(getActivity());
		initializeViewComponents(rootView);

		isFragmentViewInitialized = true;

		if (notificationMode == NotificationMode.NOTIFY_OFFLINE) {
			notifyOfflineMode();
		} else if (notificationMode == NotificationMode.NOTIFY_ONLINE) {
			notifyOnlineMode();
		}

		return rootView;
	}

	private void initializeViewData() {

		// @formatter:off
		allUserActions = new ArrayList<>();
		myWorkUserActions = new ArrayList<>();
		myUserActions = new ArrayList<>();
		starredUserActions = new ArrayList<>();
		outboxUserActions = new ArrayList<>();
		// @formatter:on
	}

	private void initializeViewAdapters(Context context) {

		// @formatter:off
		allDocumentsViewAdapter = new DocumentListItemViewAdapter(context, allUserActions);
		myWorkDocumentsViewAdapter = new DocumentListItemViewAdapter(context, myWorkUserActions);
		myDocumentsViewAdapter = new DocumentListItemViewAdapter(context, myUserActions);
		starredDocumentsViewAdapter = new DocumentListItemViewAdapter(context, starredUserActions);
		outboxDocumentsViewAdapter = new DocumentListItemViewAdapter(context, outboxUserActions);
		// @formatter:on

		initializeViewAdapterActionListeners();

	}

	private void resetFormFilterSelection() {

		if (formFilterSelection == null) {
			formFilterSelection = new ArrayList<FormStub>();
		} else {
			formFilterSelection.clear();
		}

		FormStub allFormsStub = new FormStub();
		allFormsStub.dbId = "0";
		allFormsStub.webId = "0";
		allFormsStub.name = "All Forms";

		formFilterSelection.add(allFormsStub);

		currentlySelectedFormFilter = allFormsStub;

	}

	private void addFormFilters(List<FormStub> formIdNameStubList) {

		for (FormStub stub : formIdNameStubList) {
			formFilterSelection.add(stub);
		}

	}

	private void initializeViewComponents(View rootView) {

		initializeViewPager(rootView);
		initializeActionBarTabs();
		initializeSpinnerTitleBar(rootView);
		initializeMessageNotification(rootView);
		initializeLoadingMessageViews(rootView);
		initializeViewAnimation(rootView);

	}

	private void initializeViewPagerFragments() {

		viewFragments = new ArrayList<Fragment>();

		// @formatter:off
		homeViewFragment 				= DocumentListViewFragment.createInstance("Home", allDocumentsViewAdapter);
		myWorkViewFragment 				= DocumentListViewFragment.createInstance("My Work", myWorkDocumentsViewAdapter);
		myDocumentsViewFragment 		= DocumentListViewFragment.createInstance("My Documents", myDocumentsViewAdapter);
		starredDocumentsViewFragment 	= DocumentListViewFragment.createInstance("Starred Documents", starredDocumentsViewAdapter);
		outboxDocumentViewFragment 		= DocumentListViewFragment.createInstance("Outbox", outboxDocumentsViewAdapter);
		// @formatter:on

		viewFragments.add(homeViewFragment);
		viewFragments.add(myWorkViewFragment);
		viewFragments.add(myDocumentsViewFragment);
		viewFragments.add(starredDocumentsViewFragment);
		viewFragments.add(outboxDocumentViewFragment);

	}

	private void initializeViewPagerFragmentsActionListeners() {

		DocumentListViewFragmentActionListener documentListViewActionListener = new DocumentListViewFragmentActionListener() {

			@Override
			public void onRefreshCommand() {
				listener.onRefreshDocumentsRequested();
				startSwipeRefresh();
			}

			@Override
			public void onUserActionListItemSelected(UserActionListViewItem userAction) {
				listener.onOpenDocumentCommand(userAction.documentDbId);
			}

		};

		DocumentListViewFragmentActionListener outboxDocumentListViewActionListener = new DocumentListViewFragmentActionListener() {

			@Override
			public void onRefreshCommand() {
				listener.onRefreshOutboxDocumentsRequested();
			}

			@Override
			public void onUserActionListItemSelected(UserActionListViewItem userAction) {
				listener.onOpenOutboxDocumentCommand(userAction.documentDbId, userAction.isOutgoing);
			}

		};

		homeViewFragment.setActionListener(documentListViewActionListener);
		myWorkViewFragment.setActionListener(documentListViewActionListener);
		myDocumentsViewFragment.setActionListener(documentListViewActionListener);
		starredDocumentsViewFragment.setActionListener(documentListViewActionListener);

		outboxDocumentViewFragment.setActionListener(outboxDocumentListViewActionListener);

	}

	private void initializeViewAdapterActionListeners() {

		DocumentListItemActionListener documentListViewAdapterListener = new DocumentListItemActionListener() {

			@Override
			public void onClickedActions(UserActionListViewItem userActionListViewItem) {
				listener.onOpenActionsDialogCommand(userActionListViewItem);
			}

			@Override
			public void onDocumentStarMarked(UserActionListViewItem userActionListViewItem,
			        DocumentStar newDocumentStar) {
				listener.onMarkDocumentStarCommand(userActionListViewItem, newDocumentStar);

			}

			@Override
			public void onClickedComments(UserActionListViewItem userActionListViewItem) {
				listener.onOpenDocumentCommentsCommand(userActionListViewItem);
			}

		};

		allDocumentsViewAdapter.setActionListener(documentListViewAdapterListener);
		myWorkDocumentsViewAdapter.setActionListener(documentListViewAdapterListener);
		myDocumentsViewAdapter.setActionListener(documentListViewAdapterListener);
		starredDocumentsViewAdapter.setActionListener(documentListViewAdapterListener);
		outboxDocumentsViewAdapter.setActionListener(documentListViewAdapterListener);

	}

	private void initializeTabIcons() {

		ImageView ivHome = new ImageView(getActivity());
		ivHome.setImageResource(R.drawable.homel);

		ImageView ivMyapproval = new ImageView(getActivity());
		ivMyapproval.setImageResource(R.drawable.myapproval);

		ImageView ivMyrequest = new ImageView(getActivity());
		ivMyrequest.setImageResource(R.drawable.myrequestl);

		ImageView ivStarred = new ImageView(getActivity());
		ivStarred.setImageResource(R.drawable.starredl);

		ImageView ivMypending = new ImageView(getActivity());
		ivMypending.setImageResource(R.drawable.mypendingl);

		tabIcons = new ArrayList<ImageView>();

		tabIcons.add(ivHome);
		tabIcons.add(ivMyapproval);
		tabIcons.add(ivMyrequest);
		tabIcons.add(ivStarred);
		tabIcons.add(ivMypending);

	}

	private void initializeActionBarTabs() {

		initializeViewPagerFragments();
		initializeViewPagerFragmentsActionListeners();
		initializeTabIcons();

		abMainActionBar = getActivity().getActionBar();
		abMainActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

		MainTabViewTabListener tabListener = new MainTabViewTabListener();

		for (int i = 0; i < viewFragments.size(); i++) {

			ActionBar.Tab tab = abMainActionBar.newTab();
			tab.setTabListener(tabListener);
			tab.setCustomView(tabIcons.get(i));

			abMainActionBar.addTab(tab);

		}

	}

	private void initializeViewPager(View rootView) {
		vpMainViewPager = (ViewPager) rootView.findViewById(R.id.Main_vpMainViewPager);
		vpMainViewPager.setAdapter(new MainViewPagerAdapter(getFragmentManager()));
		vpMainViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

			@Override
			public void onPageSelected(int index) {
				abMainActionBar.setSelectedNavigationItem(index);
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {}
		});
	}

	@SuppressLint("InflateParams")
	private void initializeSpinnerTitleBar(View rootView) {

		// get the default title bar of the view
		int titleBarResourceId = Resources.getSystem().getIdentifier("action_bar_title", "id",
		        "android");
		View titleBarView = getActivity().findViewById(titleBarResourceId);

		// initialize the spinner view that will replace the default title bar
		formfilterAdapter = new ArrayAdapter<FormStub>(getActivity(),
		        R.layout.view_form_filter_item, formFilterSelection);
		formfilterAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

		spFormFilter = (Spinner) getActivity().getLayoutInflater().inflate(
		        R.layout.view_form_filter_spinner, null);

		spFormFilter.setAdapter(formfilterAdapter);

		ViewGroupUtils.replaceView(titleBarView, spFormFilter);

		spFormFilter.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

				FormStub selectedFilter = formFilterSelection.get(position);

				if (!selectedFilter.dbId.equals(currentlySelectedFormFilter.dbId)) {
					currentlySelectedFormFilter = selectedFilter;
					listener.onFormFilterChanged(selectedFilter);
				}

			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {}

		});

	}

	private void initializeMessageNotification(View rootView) {

		llMessageContainer = (LinearLayout) rootView.findViewById(R.id.Main_llMessageContainer);
		llMessageContainer.setVisibility(View.GONE);

		tvMessageNotification = (TextView) rootView.findViewById(R.id.Main_tvMessage);

		bRetryConnection = (Button) rootView.findViewById(R.id.Main_bRetry);
		bRetryConnection.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				listener.onRetryConnectionRequested();
			}

		});

	}

	private void initializeLoadingMessageViews(View rootView) {

		llLoadingMessageContainer = (LinearLayout) rootView
		        .findViewById(R.id.Main_llLoadingMessageContainer);
		tvLoadingMessage = (TextView) rootView.findViewById(R.id.Main_tvLoadingMessage);

	}

	private void initializeViewAnimation(View rootView) {
		fadeInAnimation = AnimationUtils.loadAnimation(getActivity(), R.animator.fade_in);

		fadeOutAnimation = AnimationUtils.loadAnimation(getActivity(), R.animator.fade_out);

	}

	// ========================================================================
	// Functional View Methods

	public void displayLoadingMessage(String message) {

		llLoadingMessageContainer.setVisibility(View.VISIBLE);
		tvLoadingMessage.setText(message);

	}

	public void dismissLoadingMessage() {

		llLoadingMessageContainer.setVisibility(View.GONE);
		tvLoadingMessage.setText("");

	}

	public void dismissConnectionModeNotification() {

		bRetryConnection.setVisibility(View.INVISIBLE);
		llMessageContainer.setAnimation(fadeInAnimation);
		llMessageContainer.setVisibility(View.INVISIBLE);

	}

	public void notifyOnlineMode() {

		tvMessageNotification.setText(PROMPT_HAS_CONNECTION);
		bRetryConnection.setVisibility(View.INVISIBLE);

		llMessageContainer.setAnimation(fadeInAnimation);
		llMessageContainer.setVisibility(View.VISIBLE);
		llMessageContainer.setBackgroundColor(Color.parseColor(COLOR_INFO));
		llMessageContainer.postDelayed(new Runnable() {

			@Override
			public void run() {
				llMessageContainer.setVisibility(View.GONE);
				llMessageContainer.setAnimation(fadeOutAnimation);
			}

		}, 5000);
	}

	public void notifyOfflineMode() {

		tvMessageNotification.setText(PROMPT_NO_CONNECTION);
		bRetryConnection.setVisibility(View.VISIBLE);
		llMessageContainer.setAnimation(fadeInAnimation);
		llMessageContainer.setVisibility(View.VISIBLE);
		llMessageContainer.setBackgroundColor(Color.parseColor(COLOR_ERROR));

	}

	public void clearViewData() {

		allUserActions.clear();
		myWorkUserActions.clear();
		myUserActions.clear();
		starredUserActions.clear();
		outboxUserActions.clear();

		// update view
		allDocumentsViewAdapter.notifyDataSetChanged();
		myWorkDocumentsViewAdapter.notifyDataSetChanged();
		myDocumentsViewAdapter.notifyDataSetChanged();
		starredDocumentsViewAdapter.notifyDataSetChanged();
		outboxDocumentsViewAdapter.notifyDataSetChanged();

	}

	private void addOrUpdateViewDataOfUserActionList(UserActionListViewItem newViewData,
	        List<UserActionListViewItem> list, ViewAddMode viewAddMode) {

		boolean userActionExisting = false;

		// search for the new view data in the list, if it is existing mark the new view
		// data as an update
		int listSize = list.size();
		for (int i = 0; i < listSize; i++) {
			if (newViewData.documentDbId.equals(list.get(i).documentDbId)) {
				newViewData.updateType = UpdateType.UPDATE;
				list.remove(i);
				userActionExisting = true;
				break;
			}

		}

		// if the new view data is not an update, mark it as a new view data
		if (!userActionExisting) {
			if (newViewData.updateType != UpdateType.CURRRENT) {
				newViewData.updateType = UpdateType.NEW;
			}
		}

		if (viewAddMode == ViewAddMode.APPEND) {
			list.add(newViewData);
		} else {
			// move the updated item to the top of the list
			list.add(0, newViewData);
		}

	}

	public void updateDocumentStarInList(String documentDbId, DocumentStar star,
	        List<UserActionListViewItem> list) {

		int listSize = list.size();
		for (int i = 0; i < listSize; i++) {

			if (documentDbId.equals(list.get(i).documentDbId)) {
				list.get(i).isStarred = (star == DocumentStar.STARRED);
				// FLLogger.d(TAG, list.get(i).isStarred ? "Starred" : "Unstarred");
				break;
			}

		}
	}

	public void initializeViewData(List<UserActionListViewItem> newViewDataList, ViewDataType type) {
		switch (type) {
			case ALL: {
				allUserActions.clear();
				allUserActions.addAll(newViewDataList);
			}
				break;
			case MY_WORK: {
				myWorkUserActions.clear();
				myWorkUserActions.addAll(newViewDataList);
			}
				break;
			case MY_ACTIONS: {
				myUserActions.clear();
				myUserActions.addAll(newViewDataList);
			}
				break;
			case STARRED: {
				starredUserActions.clear();
				starredUserActions.addAll(newViewDataList);
			}
				break;
			case OUTBOX: {
				outboxUserActions.clear();
				outboxUserActions.addAll(newViewDataList);
			}
				break;
		}

		notifyDataSetChanged(type);

	}

	public void addViewData(UserActionListViewItem newViewData, ViewDataType type,
	        ViewAddMode viewAddMode) {

		switch (type) {
			case ALL: {
				addOrUpdateViewDataOfUserActionList(newViewData, allUserActions, viewAddMode);
			}
				break;
			case MY_WORK: {
				addOrUpdateViewDataOfUserActionList(newViewData, myWorkUserActions, viewAddMode);
			}
				break;
			case MY_ACTIONS: {
				addOrUpdateViewDataOfUserActionList(newViewData, myUserActions, viewAddMode);
			}
				break;
			case STARRED: {
				addOrUpdateViewDataOfUserActionList(newViewData, starredUserActions, viewAddMode);
			}
				break;
			case OUTBOX: {
				addOrUpdateViewDataOfUserActionList(newViewData, outboxUserActions, viewAddMode);
			}
				break;
		}

		notifyDataSetChanged(type);

	}

	public void removeViewData(UserActionListViewItem viewDataToRemove, ViewDataType type) {

		switch (type) {
			case ALL: {
				allUserActions.remove(viewDataToRemove);
			}
				break;
			case MY_WORK: {
				myWorkUserActions.remove(viewDataToRemove);
			}
				break;
			case MY_ACTIONS: {
				myUserActions.remove(viewDataToRemove);
			}
				break;
			case STARRED: {
				starredUserActions.remove(viewDataToRemove);
			}
				break;
			case OUTBOX: {
				outboxUserActions.remove(viewDataToRemove);
			}
				break;
		}

		notifyDataSetChanged(type);

	}

	public void startSwipeRefresh() {

		homeViewFragment.startSwipeRefresh();
		myWorkViewFragment.startSwipeRefresh();
		myDocumentsViewFragment.startSwipeRefresh();
		starredDocumentsViewFragment.startSwipeRefresh();

		// outboxDocumentViewFragment
	}

	public void stopDocumentsUpdateSwipeRefresh() {

		homeViewFragment.stopSwipeRefresh();
		myWorkViewFragment.stopSwipeRefresh();
		myDocumentsViewFragment.stopSwipeRefresh();
		starredDocumentsViewFragment.stopSwipeRefresh();
	}

	public void stopOutboxUpdateSwipeRefesh() {
		outboxDocumentViewFragment.stopSwipeRefresh();
	}

	public void notifyDataSetChanged() {
		allDocumentsViewAdapter.notifyDataSetChanged();
		myWorkDocumentsViewAdapter.notifyDataSetChanged();
		myDocumentsViewAdapter.notifyDataSetChanged();
		starredDocumentsViewAdapter.notifyDataSetChanged();
	}

	public void notifyDataSetChanged(ViewDataType type) {

		if (isFragmentViewInitialized) {
			switch (type) {
				case ALL: {
					allDocumentsViewAdapter.notifyDataSetChanged();
				}
					break;
				case MY_WORK: {
					myWorkDocumentsViewAdapter.notifyDataSetChanged();
				}
					break;
				case MY_ACTIONS: {
					myDocumentsViewAdapter.notifyDataSetChanged();
				}
					break;
				case STARRED: {
					starredDocumentsViewAdapter.notifyDataSetChanged();
				}
					break;
				case OUTBOX: {
					outboxDocumentsViewAdapter.notifyDataSetChanged();
				}
					break;
			}
		}

	}

	// ========================================================================
	// Getters & Setters

	public List<FormStub> getFormFilterSelection() {
		return formFilterSelection;
	}

	public void setFormFilterSelection(List<FormStub> newFormFilterSelection) {

		FLLogger.d(TAG, "setting form filter selection");

		// reset the form filter selection, then add the form names
		resetFormFilterSelection();
		addFormFilters(newFormFilterSelection);

		formfilterAdapter.notifyDataSetChanged();
	}

	// ========================================================================
	// Adapters and Event Implementation Private Classes

	private class MainViewPagerAdapter extends FragmentPagerAdapter {

		public MainViewPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int index) {
			return viewFragments.get(index);
		}

		@Override
		public int getCount() {
			return 5;
		}

	}

	private class MainTabViewTabListener implements TabListener {

		@Override
		public void onTabReselected(Tab tab, FragmentTransaction fragmentTransaction) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onTabSelected(Tab tab, FragmentTransaction fragmentTransaction) {
			vpMainViewPager.setCurrentItem(tab.getPosition());
		}

		@Override
		public void onTabUnselected(Tab tab, FragmentTransaction fragmentTransaction) {
			// TODO Auto-generated method stub

		}

	}

	// ========================================================================
	// Interfaces

	public static interface MainViewActivityActionListener {
		public void onFormFilterChanged(FormStub stub);

		public void onRetryConnectionRequested();

		public void onRefreshDocumentsRequested();

		public void onRefreshOutboxDocumentsRequested();

		public void onOpenDocumentCommand(String documentDbId);

		public void onOpenOutboxDocumentCommand(String documentDBId, boolean isOutgoing);

		public void onOpenDocumentCommentsCommand(UserActionListViewItem userActionListViewItem);

		public void onMarkDocumentStarCommand(UserActionListViewItem userActionListViewItem,
		        DocumentStar newDocumentStar);

		public void onOpenActionsDialogCommand(UserActionListViewItem userActionListViewItem);

	}

}
